Release 10.1A: OpenEdge Development:
Programming Interfaces
Initializing and uninitializing MEMPTR variables
After declaring a
Note: You can also allocate the memory region for aMEMPTRvariable, you must initialize it before you can use it. In general, to initialize aMEMPTRvariable, you use theSET-SIZEstatement to allocate a region of memory and associate it with the variable.MEMPTRvariable using a shared library routine. In this case, you must still use theSET-SIZEstatement to initialize the size of the returned memory region in Progress.Initializing MEMPTR variables using the SET-SIZE statement
This is the syntax for the
SET-SIZEstatement:
The value
mptr-nameis the name of aMEMPTRvariable, andexpressionis an integer expression specifying the size, in bytes, of a memory region associated withmptr-name. The value ofexpressioncan also be zero (0), which frees any memory previously allocated tomptr-name. Progress uses this size to perform bounds checking that ensures you do not read or write to portions of memory outside of the specified region.If
mptr-nameis uninitialized (that is, defined but not associated with any memory region) andexpressionis greater than zero (0), theSET-SIZEstatement allocates a memory region whose size is specified byexpression, and associates it withmptr-name. Ifmptr-nameis already initialized andexpressionis greater than zero (0), theSET-SIZEstatement has no effect.To resize memory allocated to a
MEMPTRvariable, you must invokeSET-SIZEwith anexpressionof zero (0), then invokeSET-SIZEwith anexpressionequal to the new allocation.Checking a MEMPTR variable for initialization
You might not be sure whether a particular
MEMPTRvariable is already initialized when you try to initialize it. You can verify that the variable is initialized and obtain the size of its memory region using theGET-SIZEfunction. This is the syntax for theGET-SIZEfunction:
If
Note: To return a memory size greater than zero (0), the variable must be fully initialized with themptr-nameis initialized, theGET-SIZEfunction returns the size of its memory region. Otherwise, it returns zero (0).SET-SIZEstatement, not just allocated by a shared library routine.Freeing memory associated with a MEMPTR variable
The region of memory associated with a
MEMPTRvariable remains allocated until it is freed. Progress does not automatically free the memory for you. It is up to you to ensure that the memory is freed.You can free the memory using
Note: When working with shared library routines, you must fully understand the memory management provided by these routines before usingSET-SIZEwith anexpressionof zero (0).SET-SIZEthen deallocates (frees) any memory region associated withmptr-name. This makesmptr-nameuninitialized.MEMPTRvariables with them effectively.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |